package ch.usi.inf.pf2.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import ch.usi.inf.pf2.editor.UndoRedoStack;
import ch.usi.inf.pf2.gui.JSpreadSheetGUI;
import ch.usi.inf.pf2.gui.SpreadSheetTableModel;

/**
 * Listener for the menu and button "Redo"
 * 
 * @author Lorenzo Baracchi <lorenzo.baracchi@usi.ch>, Ebrisa Savina
 *         Mastrodicasa
 * 
 */
public class RedoActionListener implements ActionListener
{
    private JSpreadSheetGUI spreadTable;

    public RedoActionListener(JSpreadSheetGUI spreadTable)
    {
	   this.spreadTable = spreadTable;
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
	   UndoRedoStack stack = spreadTable.getStack();
	   ch.usi.inf.pf2.editor.Action a = stack.redo();
	   a.evaluate();
	   SpreadSheetTableModel tb = (SpreadSheetTableModel) spreadTable
			 .getTable().getModel();
	   tb.fireTableDataChanged();
	   spreadTable.getSheet().setHasBeenSaved(false);
    }

}
